<?php

	class client{
	
		var $client;
		var $company;
		var $address;
		var $cellNo;
		var $telNo;
		var $faxNo;
		var $emailAdd;
		
		var $search;
		
		function sendClientDetails($client, $company, $address, $cellNo, $telNo, $faxNo, $emailAdd){
			$this->client = $client;
			$this->company = $company;
			$this->address = $address;
			$this->cellNo = $cellNo;
			$this->telNo = $telNo;
			$this->faxNo = $faxNo;
			$this->emailAdd = $emailAdd;
		}
		
		function search($search){

			$query = "SELECT * FROM client WHERE company like '%" . $search . "%' or address like '%" . $search . "%' or emailAdd like '%" . $search . "%' or cellNo like '%" . $search . "%' or telNo like '%" . $search . "%' or faxNo like '%" . $search . "%'";
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', 'root', '');
			mysql_select_db('eais', $link);
			$result = mysql_query($query);
			$size = mysql_num_rows($result);			
			if($size>0){
				echo "<table id=\"myTable\">";
				echo "<thead>";
				echo "<tr>"; 
				echo "	<th>Company</th>"; 
				echo "	<th>Address</th>"; 
				echo "	<th>Email Address</th>"; 
				echo "	<th>Cellphone Numbre</th>"; 
				echo "	<th>Telephone Number</th>"; 
				echo "	<th>Faxphone Number</th>"; 
				echo "</tr>"; 
				echo "</thead>"; 

				echo "<tbody>"; 
				while($rows = mysql_fetch_assoc($result)){
				echo "	<tr>"; 
				echo "		<td>".$rows['company']."</td>"; 
				echo "		<td>".$rows['address']."</td>"; 
				echo "		<td>".$rows['emailAdd']."</td>"; 
				echo "		<td>".$rows['cellNo']."</td>"; 
				echo "		<td>".$rows['telNo']."</td>"; 
				echo "		<td>".$rows['faxNo']."</td>"; 
				echo "	</tr>";
				}
				echo "</tbody>"; 
				echo "</table>"; 
			}
			else
				echo "No Data";
		}
		
		function viewInfo($clientToView){
			$query = "SELECT company, address, emailAdd, cellNo, telNo, faxNo FROM client WHERE company='$clientToView' ";
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			$result = mysql_query($query);
			
			while($row = mysql_fetch_assoc($result)){
				$client = $row['company'];
				$company = $row['company'];
				$address = $row['address'];
				$emailAdd = $row['emailAdd'];
				$cellNo = $row['cellNo'];
				$telNo = $row['telNo'];
				$faxNo = $row['faxNo'];
			}			
			echo "	<script>";

			echo "		client = \"".$client."\";";
			echo "		company = \"".$company."\";";
			echo "		address = \"".$address."\";";
			echo "		cellNo = \"".$cellNo."\";";
			echo "		telNo = \"".$telNo."\";";
			echo "		faxNo = \"".$faxNo."\";";
			echo "		emailAdd = \"".$emailAdd."\";";
			
			echo "		from = \"view\";";

			echo "		$.post('viewClientInfo.php',{";

			echo "			client: client,";			
			echo "			company: company,";
			echo "			address: address,";
			echo "			cellNo: cellNo,";
			echo "			telNo: telNo,";
			echo "			faxNo: faxNo,";
			echo "			emailAdd: emailAdd,";
			
			echo "			from:from";
			
			echo "			},function(data){";
			echo "				$('#view').html(data);";
			echo "			}";
			echo "		);";
			echo "	</script>";			
		}
		
		function retrieve(){
			$query = "SELECT company FROM client ORDER BY company";
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			$result = mysql_query($query);
			$size = mysql_num_rows($result);
			$sizeContainer = $size*20+50;
			if($size>0){
			$count=0;		
						
			echo "<div id=\"lHead\">";
			echo "	<span id=\"listHeader\">CLIENTS</span>";
			echo "</div>";
					
			echo "<div id=\"lBody\">";
			echo "	<table id=\"clientTable\" cellspacing='0' cellpadding='0'>";
						while($rows=mysql_fetch_assoc($result)){
			echo "			<tr>";
			if($count%2==0){
				echo "				<td id=\"inner1".$count."\" style=\"background-color:white;\" onclick=\"selectClient('".$rows['company']."');\" onmouseover=\"highlight('".$count."');\" onmouseout=\"unhighlight('".$count."');\">";
				echo "					 <div id=\"inner2\">".$rows['company']."</div>";
				echo "				</td>";
			}
			else{
				echo "				<td id=\"inner1".$count."\" style=\"background-color:#e7e7e7;\"  onclick=\"selectClient('".$rows['company']."');\" onmouseover=\"highlight('".$count."');\" onmouseout=\"unhighlight('".$count."');\">";
				echo "					 <div id=\"inner2\">".$rows['company']."</div>";
				echo "				</td>";
			}
			echo "			</tr>";
						$count++;
						}
			echo "	</table>";
			echo "</div>";
			
			echo "<div id=\"lLower\">";
			echo "</div>";

				if($from=="edit")
					echo "<center><input type=\"button\" value=\"Submit\" id=\"buttonSubmit\" onclick=\"submitClientData();return false;\" /></center>";
			}
			else
				echo "No Data for Client";
			echo "<input type=\"button\" id=\"addButton\" value=\"Add\" onclick=\"addClient('add');\" />";
		}
		
		function add(){
			$user="root";
			$password="";
			$database="eais";	
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			mysql_query("insert into client(name,company,address,cellNo,telNo,faxNo,emailAdd) values('$this->company', '$this->company', '$this->address', '$this->cellNo', '$this->telNo', '$this->faxNo', '$this->emailAdd')", $link);
			if(mysql_error($link)!="")
				echo "already exist";
			else
				echo "You have successfuly added ".$this->company."<br />";
			echo "<input type='button' value='Add Another' id='addAnother' onclick=\"showForm();return false;\">";
		}

		function retrieveInfo($client){
			$user="root";
			$password="";
			$database="eais";		
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			$result = mysql_query("SELECT company, address, cellNo, telNo, faxNo, emailAdd FROM client where company='$client'");
		
			$rows=mysql_fetch_assoc($result);
			echo $client;
			echo "<input type='hidden' name='client' value=\"".$client."\" id='client2' /><br />";
			echo "Company<br /><input type='text' name='company' value=\"".$rows['company']."\" id='company' /><br />";
			echo "Address<br /><input type='text' name='address' value=\"".$rows['address']."\" id='address' /><br />";
			echo "Cellphone Number<br /><input type='text' name='cellNo' value=\"".$rows['cellNo']."\" id='cellNo' /><br />";
			echo "Telephone Number<br /><input type='text' name='telNo' value=\"".$rows['telNo']."\" id='telNo' /><br />";
			echo "Fax Number<br /><input type='text' name='faxNo' value=\"".$rows['faxNo']."\" id='faxNo' /><br />";
			echo "Email Address<br /><input type='text' name='emailAdd' value=\"".$rows['emailAdd']."\" id='emailAdd' /><br />";
			echo "<input type='button' value='Submit' id='buttonSubmit' onclick=\"editSelectedClient('submit');return false;\" />";
			echo "<input type='button' value='Cancel' id='buttonCancel' onclick='cancel();return false;' />";
		}
		
		function edit(){	
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			$queryClient = "UPDATE client SET name = '$this->company', company = '$this->company', address = '$this->address', cellNo = '$this->cellNo', telNo = '$this->telNo', faxNo = '$this->faxNo', emailAdd = '$this->emailAdd' WHERE company = '$this->client'";
			$queryEnzyme = "UPDATE enzyme SET client = '$this->company' WHERE client = '$this->client'";
			mysql_query($queryClient);
			mysql_query($queryEnzyme);
		}
		
		function set_company($new_company) {
			$this->company = $new_company;
		}
		
		function set_address($new_address) {
			$this->company = $new_address;
		}
		
		function set_cellNo($new_cellNo) {
			$this->company = $new_cellNo;
		}
		
		function set_telNo($new_telNo) {
			$this->company = $new_telNo;
		}
		
		function set_faxNo($new_faxNo) {
			$this->company = $new_faxNo;
		}
		
		function set_emailAdd($new_emailAdd) {
			$this->company = $new_emailAdd;
		}

		function get_company() {
			return $this->company;
		}
		
		function get_address() {
			return $this->address;
		}
		
		function get_cellNo() {
			return $this->cellNo;
		}
		
		function get_telNo() {
			return $this->telNo;
		}
		
		function get_faxNo() {
			return $this->faxNo;
		}

		function get_emailAdd() {
			return $this->emailAdd;
		}
	
	}
	
?>